//
//  HomeQuickIdeaCell.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/23.
//

#import "HomeQuickIdeaCell.h"

@interface HomeQuickIdeaCell()
@property (nonatomic,strong) UIView * bgView;
@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) YYLabel * infoLabel;
@property (nonatomic,strong) UIButton * nextBtn;
@end

@implementation HomeQuickIdeaCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(343 * FMScaleX, 113 * FMScaleX));
        make.center.equalTo(@0);
    }];
    [self.bgView addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(22 * FMScaleX);
        make.top.mas_offset(13 * FMScaleX);
    }];
    [self.bgView addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(310 * FMScaleX, 58 * FMScaleX));
        make.centerX.equalTo(@0);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(5 * FMScaleX);
    }];
    
    NSMutableAttributedString *normalPriceStr = [[NSMutableAttributedString alloc] initWithString:self.infoLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing =  5 * FMScaleX; // 设置行间距为10
    [normalPriceStr yy_setParagraphStyle:paragraphStyle range:NSMakeRange(0, normalPriceStr.length)];
    NSMutableAttributedString * obj = [NSMutableAttributedString yy_attachmentStringWithContent:({
        self.nextBtn;
    }) contentMode:UIViewContentModeRight attachmentSize:CGSizeMake(140 * FMScaleX , 30 * FMScaleX) alignToFont:self.infoLabel.font alignment:YYTextVerticalAlignmentCenter];
    [normalPriceStr insertAttributedString:obj atIndex:normalPriceStr.length];
    self.infoLabel.attributedText = normalPriceStr;
    self.infoLabel.font = Regular(13);
    self.infoLabel.textColor = RDRGB(0xAD7D62);
}

-(void)nextBtnAction{
    
    FLodingStr(@"正在处理")
    [[BCLRingManager shared] getBlcConnectWithCompletion:^(BOOL state) {
        FHideLoding
        if (!state) {
            FhudShowStr(@"设备未连接");
            id vc = [[NSClassFromString(@"HomeJoinVC") alloc]init];
            [[UIViewController findNavigationController] pushViewController:vc
                                                                   animated:YES];
            return;
        }else{
            id vc = [[NSClassFromString(@"HomeAllCheckVC") alloc]init];
            [[UIViewController findNavigationController] pushViewController:vc
                                                                   animated:YES];
        }
    }];
}

-(UIView *)bgView{
    
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = RDRGB(0xF3EDE7);
        [_bgView setCornerRadius:9 * FMScaleX borderWidth:1 borderColor:RDRGB(0xC8B7A7)];
    }
    return _bgView;
}
-(UILabel *)nameLabel{
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = Bold(20);
        _nameLabel.text = @"健康建议";
        _nameLabel.textColor = RDRGB(0xAD7D62);
    }
    return _nameLabel;
}

-(YYLabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[YYLabel alloc]init];
        _infoLabel.font = Regular(13);
        _infoLabel.textColor = RDRGB(0xAD7D62);
        _infoLabel.numberOfLines = 2;
        _infoLabel.text = @"为了更准确的分析您的身体健康状况，我们准备了更全面的身体健康检测～   ";
    }
    return _infoLabel;
}

-(UIButton *)nextBtn{
    
    if (!_nextBtn) {
        _nextBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 140 * FMScaleX, 30 * FMScaleX)];
        [_nextBtn setBackgroundColor:RDRGB(0xAD7D62)];
        [_nextBtn setTitle:@"全面健康检测 >" forState:UIControlStateNormal];
        [_nextBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [_nextBtn setCornerRadius:15 * FMScaleX];
        [_nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}
@end
